package com.vcms.view.simulation.uicomponent.button;

import java.awt.Panel;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

import java.awt.*;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class ButtonItem extends Panel {

	final public static int DEFAULT_LEN = 5;
	public final static char FLOW = 'a';
	public final static char GRID = 'b';

	public final static Color DT_COLOR = Color.darkGray;

	public final static Color ACT_COLOR = Color.white;

	private Button btn;
	// private TextField value;
	private Label value;

	public ButtonItem(String bn, char lt) {

		btn = new Button(bn);
		value = new Label("              ");
		value.setBackground(Color.white);

		if (lt == FLOW)
			this.setLayout(new FlowLayout());
		else if (lt == GRID)
			this.setLayout(new GridLayout(1, 2));

		this.add(btn);
		this.add(value);
	}

	public void addListener(ActionListener l) {
		btn.addActionListener(l);
	}

	public void setActionCommand(String cmd) {
		btn.setActionCommand(cmd);
	}

	public void setActive(boolean st) {
		btn.setEnabled(st);
		value.setEnabled(st);
	}

	public void setTextBackground(Color cl) {
		value.setBackground(cl);
	}

	public void clear() {
		setTextBackground(DT_COLOR);
		value.setText("");
	}

	public void setValue(int vl) {
		String sqt;

		sqt = String.valueOf(vl);
		value.setBackground(ACT_COLOR);
		value.setText(sqt);
	}

	public void setValue(String vl) {
		value.setBackground(ACT_COLOR);
		value.setText(vl);
	}
}